<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>判断给定的 array 是否为 list</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.array-intersect.html">« array_intersect</a></li>
      <li style="float: right;"><a href="function.array-key-exists.html">array_key_exists »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.array.html">数组 函数</a></li>
    <li>判断给定的 array 是否为 list</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.array-is-list" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">array_is_list</h1>
  <p class="verinfo">(PHP 8 &gt;= 8.1.0)</p><p class="refpurpose"><span class="refname">array_is_list</span> &mdash; <span class="dc-title">判断给定的 <code class="parameter">array</code> 是否为 list</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.array-is-list-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>array_is_list</strong></span>(<span class="methodparam"><span class="type">array</span> <code class="parameter">$array</code></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   判断指定的 <code class="parameter">array</code> 是否是 list。如果 <span class="type">array</span> 的 key 由 <code class="literal">0</code> 到 <code class="literal">count($array)-1</code> 的连续数字组成，则该数组就是 list。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.array-is-list-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">array</code></dt>

     <dd>

      <p class="para">
       被检测的 <span class="type">array</span>。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.array-is-list-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   如果 <code class="parameter">array</code> 是 list 就返回 <strong><code>true</code></strong>，否则返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.array-is-list-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4921">
    <p><strong>示例 #1 <span class="function"><strong>array_is_list()</strong></span> 示例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />array_is_list</span><span style="color: #007700">([]);&nbsp;</span><span style="color: #FF8000">//&nbsp;true<br /></span><span style="color: #0000BB">array_is_list</span><span style="color: #007700">([</span><span style="color: #DD0000">'apple'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">]);&nbsp;</span><span style="color: #FF8000">//&nbsp;true<br /></span><span style="color: #0000BB">array_is_list</span><span style="color: #007700">([</span><span style="color: #0000BB">0&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'apple'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'orange'</span><span style="color: #007700">]);&nbsp;</span><span style="color: #FF8000">//&nbsp;true<br /><br />//&nbsp;key&nbsp;未从&nbsp;0&nbsp;开始<br /></span><span style="color: #0000BB">array_is_list</span><span style="color: #007700">([</span><span style="color: #0000BB">1&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'apple'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'orange'</span><span style="color: #007700">]);&nbsp;</span><span style="color: #FF8000">//&nbsp;false<br /><br />//&nbsp;key&nbsp;的顺序不正确<br /></span><span style="color: #0000BB">array_is_list</span><span style="color: #007700">([</span><span style="color: #0000BB">1&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'apple'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'orange'</span><span style="color: #007700">]);&nbsp;</span><span style="color: #FF8000">//&nbsp;false<br /><br />//&nbsp;包含非整数&nbsp;key<br /></span><span style="color: #0000BB">array_is_list</span><span style="color: #007700">([</span><span style="color: #0000BB">0&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'apple'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'foo'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'bar'</span><span style="color: #007700">]);&nbsp;</span><span style="color: #FF8000">//&nbsp;false<br /><br />//&nbsp;非连续&nbsp;key<br /></span><span style="color: #0000BB">array_is_list</span><span style="color: #007700">([</span><span style="color: #0000BB">0&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'apple'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'bar'</span><span style="color: #007700">]);&nbsp;</span><span style="color: #FF8000">//&nbsp;false<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.array-is-list-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    空数组也会返回 <strong><code>true</code></strong>。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.array-is-list-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.array-values.html" class="function" rel="rdfs-seeAlso">array_values()</a> - 返回数组中所有的值</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>